using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VMEKOPF
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {
            #region
            #endregion
            switch (app.company)
            {
                case "YGR":
                case "SXN":
                case "TST":
                case "UBT":
                default:
                    #region
                    dwReturn["MEKMANDANT"] = "00";
                    dwReturn["MEKAGANG"] = "JS             ";
                    dwReturn["MEKMTYP"] = "JS      ";
                    dwReturn["MEKMNRKRS"] = "  ";
                    dwReturn["MEKMLFDNR"] = "0300";
                    dwReturn["MEKMPOS"] = "00";
                    dwReturn["MEKEVARHNR"] = "01";
                    dwReturn["MEKEVARUNR"] = "01";
                    dwReturn["MEKBNRKRS"] = "  ";
                    dwReturn["MEKBLFDNR"] = "0230";
                    dwReturn["MEKBPOS"] = "01";
                    dwReturn["MEKSTAKZ"] = "A";
                    dwReturn["MEKUNKLARZL"] = "0";
                    dwReturn["MEKBEM1"] = ".                                                 ";
                    dwReturn["MEKBEM2"] = "                                                  ";
                    dwReturn["MEKAENDZL"] = "0";
                    dwReturn["MEKAENDBEN"] = "        ";
                    dwReturn["MEKAENDDAT"] = "0";
                    dwReturn["MEKNEUBEN"] = "JAKV    ";
                    dwReturn["MEKNEUDAT"] = "20140920";
                    dwReturn["MEKVONMOD"] = "000";
                    dwReturn["MEKBISMOD"] = "999";
                    dwReturn["MEKWSCHLA"] = "          ";
                    dwReturn["MEKFILLER"] = "          ";
                    #endregion
                    break;
            }
        }
        public void InsertMEKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                case "SXN":
                case "TST":
                case "UBT":
                default:
                    or1.CommandText = "INSERT INTO MEKOPF ( MEKMANDANT,MEKAGANG,MEKMTYP,MEKMNRKRS,MEKMLFDNR,MEKMPOS,MEKEVARHNR,MEKEVARUNR,MEKBNRKRS,MEKBLFDNR,MEKBPOS,MEKSTAKZ,MEKUNKLARZL,MEKBEM1,MEKBEM2,MEKAENDZL,MEKAENDBEN,MEKAENDDAT,MEKNEUBEN,MEKNEUDAT,MEKVONMOD,MEKBISMOD,MEKWSCHLA,MEKFILLER)"
                   + " VALUES (:MEKMANDANT:,:MEKAGANG:,:MEKMTYP:,:MEKMNRKRS:,:MEKMLFDNR:,:MEKMPOS:,:MEKEVARHNR:,:MEKEVARUNR:,:MEKBNRKRS:,:MEKBLFDNR:,:MEKBPOS:,:MEKSTAKZ:,:MEKUNKLARZL:,:MEKBEM1:,:MEKBEM2:,:MEKAENDZL:,:MEKAENDBEN:,:MEKAENDDAT:,:MEKNEUBEN:,:MEKNEUDAT:,:MEKVONMOD:,:MEKBISMOD:,:MEKWSCHLA:,:MEKFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QMAE01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT M.* FROM  MEKOPF M"
            + " WHERE MEKMANDANT=:MEKMANDANT: AND MEKAGANG=:MEKAGANG: AND MEKMTYP=:MEKMTYP: AND MEKMNRKRS=:MEKMNRKRS: AND MEKMLFDNR=:MEKMLFDNR: AND MEKMPOS=:MEKMPOS: AND MEKEVARHNR=:MEKEVARHNR: AND MEKEVARUNR=:MEKEVARUNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QMAE02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT MEKEVARHNR||'/'||MEKEVARUNR AS KEY, MEKEVARHNR||'/'||MEKEVARUNR||MEKBEM1 AS DES,M.* FROM  MEKOPF M"
            + " WHERE MEKMANDANT=:MEKMANDANT: "
            + dwData["MEKAGANG"].ToString()
            + dwData["MEKMTYP"].ToString()
            + dwData["MEKMNRKRS"].ToString()
            + dwData["MEKMLFDNR"].ToString()
            + dwData["MEKMPOS"].ToString()
            + dwData["MEKEVARHNR"].ToString()
            + dwData["MEKEVARUNR"].ToString();
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public void DMAE00(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEKOPF"
                + " WHERE MEKMANDANT=:MEKMANDANT:  ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
        public void DMAE01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEKOPF "
            + " WHERE MEKMANDANT=:MEKMANDANT: AND MEKAGANG=:MEKAGANG: AND MEKMTYP=:MEKMTYP: AND MEKMNRKRS=:MEKMNRKRS: AND MEKMLFDNR=:MEKMLFDNR: AND MEKMPOS=:MEKMPOS: AND MEKEVARHNR=:MEKEVARHNR: AND MEKEVARUNR=:MEKEVARUNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
        public void DMAE02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM  MEKOPF"
                + " WHERE MEKMANDANT=:MEKMANDANT: AND MEKAGANG=:MEKAGANG: AND MEKMTYP=:MEKMTYP: AND MEKMNRKRS=:MEKMNRKRS: AND MEKMLFDNR=:MEKMLFDNR: AND MEKMPOS=:MEKMPOS:  ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }


        public void UpdateMEKOPF(DataRow dwData, int option = 1)
        {
            if (option == 0)
            {
                switch (app.company)
                {
                    case "YGR":
                    case "SXN":
                    case "TST":
                    case "UBT":
                    default:
                        UMAE1(dwData); break; 
                }
            } 

        }
        public void UMAE1(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE MEKOPF SET MEKMANDANT=:MEKMANDANT:,MEKAGANG=:MEKAGANG:,MEKMTYP=:MEKMTYP:,MEKMNRKRS=:MEKMNRKRS:,MEKMLFDNR=:MEKMLFDNR:,MEKMPOS=:MEKMPOS:,MEKEVARHNR=:MEKEVARHNR:,MEKEVARUNR=:MEKEVARUNR:,MEKBNRKRS=:MEKBNRKRS:,MEKBLFDNR=:MEKBLFDNR:,MEKBPOS=:MEKBPOS:,MEKSTAKZ=:MEKSTAKZ:,MEKUNKLARZL=:MEKUNKLARZL:,MEKBEM1=:MEKBEM1:,MEKBEM2=:MEKBEM2:,MEKAENDZL=:MEKAENDZL:,MEKAENDBEN=:MEKAENDBEN:,MEKAENDDAT=:MEKAENDDAT:,MEKNEUBEN=:MEKNEUBEN:,MEKNEUDAT=:MEKNEUDAT:,MEKVONMOD=:MEKVONMOD:,MEKBISMOD=:MEKBISMOD:,MEKWSCHLA=:MEKWSCHLA:,MEKFILLER=:MEKFILLER:"
            + " WHERE MEKMANDANT=:MEKMANDANT: AND MEKAGANG=:MEKAGANG: AND MEKMTYP=:MEKMTYP: AND MEKMNRKRS=:MEKMNRKRS: AND MEKMLFDNR=:MEKMLFDNR: AND MEKMPOS=:MEKMPOS: AND MEKEVARHNR=:MEKEVARHNR: AND MEKEVARUNR=:MEKEVARUNR: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); ;

            Connect2Proxy(or1);

        }
    }
}
